package com.ruoyi.project.tool.swagger.UserController;

import com.ruoyi.common.utils.BankUtil;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.SignatureValidation;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.system.domain.SysMobileUser;
import com.ruoyi.project.system.domain.SysUserBank;
import com.ruoyi.project.system.service.ISysUserBankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/mobileUser/bankCard/")
public class UserBankCardController {

    @Autowired
    private ISysUserBankService sysUserBankService;
    /**
     * 用户端绑定银行卡  登录之后
     * 传银行卡号 ——>
     */
    @SignatureValidation
    @PostMapping("bindingCard")
    public AjaxResult bindingCard(@RequestBody SysUserBank sysUserBank){
        Long mobileUserId = SecurityUtils.getLoginUser().getSysMobileUser().getMobileUserId();
        String bankCard = sysUserBank.getBankCard();
        String bankType = BankUtil.GetbankName(bankCard);
        sysUserBank.setBankType(bankType);
        sysUserBank.setMobileUserId(mobileUserId);
        SysUserBank sysUser = sysUserBankService.queryIsbankCard(sysUserBank);
        if(sysUser != null){
            return AjaxResult.error("已经绑定该卡");
        }
        return AjaxResult.success(sysUserBankService.insertSysUserBank(sysUserBank));
    }

    @SignatureValidation
    @PostMapping("deleteCard")
    public AjaxResult deleteCard(@RequestBody SysUserBank sysUserBank){
        return AjaxResult.success(sysUserBankService.deleteSysUserBankById(sysUserBank.getBankId()));
    }
}
